package com.proposition.web;

import com.proposition.commons.model.ExamCountForPaper;
import com.proposition.commons.model.User;
import com.proposition.paper.service.PaperService;
import com.proposition.support.security.CurrentUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.Optional;

/**
 * ${DESCRIPTION}
 *
 * @author 杨凯
 * @create 2017-10-30 14:57
 **/
@Controller
public class HomeController {
	@Autowired
	PaperService paperService;

	@RequestMapping("/")
	public ModelAndView index() {
		ModelAndView mv = new ModelAndView("index");
		User user = (User) CurrentUser.INSTANCE.getUser();
		mv.addObject("user", user);
		return mv;
	}
	@RequestMapping("/welcome")
	public String welcome(Model model) {
		ExamCountForPaper examCount = paperService.getExamCount(-1);
		model.addAttribute("examCount", examCount);
        Integer wenda = examCount.getXWCount() + examCount.getNKAMCount() + examCount.getFKAMCount() + examCount.getEKTNCount() + examCount.getCZCount();
        Integer XWDW = examCount.getEKXWCount() + examCount.getCRXWCount();
        Integer DXSF = examCount.getCRSFCount() + examCount.getEKSFCount() + examCount.getCZZDCount();
        Integer CTSF = examCount.getFKZTCount() + examCount.getSKZTCount() + examCount.getEKZTCount() + examCount.getNKZTCount();
        model.addAttribute("wenda", wenda);
        model.addAttribute("XWDW", XWDW);
        model.addAttribute("DXSF", DXSF);
        model.addAttribute("CTSF", CTSF);
        return "welcome";
	}
}
